<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Password_setup extends CI_Controller {

	function __construct(){
		parent::__construct();
		(!session_id()) ? session_start() : '';
		(isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] && isset($_SESSION['email']))? '':redirect('home');
		$this->load->model('lib_model');
		//$this->load->library('encryption_lib');
		
		
	}
	
	public function index()
	{

		$data ='';
		$this->load->view('password_setup/index.php',$data);
	}
	
	public function update(){
	//echo 'test';exit;
		
		$recipientPass = $this->input->post('recipient-password');
		$executorPass  = $this->input->post('executor-password');
		$userEmail	   = $_SESSION['email'];
		$recipientPassEncoded = $this->encryption_lib->encode($recipientPass);
		$executorPassEncoded =$this->encryption_lib->encode($executorPass);
		 $toUpdate = array(
			'password_executor'  => $executorPassEncoded,
			'password_recipient' => $recipientPassEncoded,
			'password_setup_status' => '1'
		
		);
		//update

		$update = $this->lib_model->update('mlme_users','email',$userEmail,$toUpdate);

		  if($update ==true){
			echo '1';
		}else{
			echo '0';
		}  
		
	}
	
	public function generatePassword(){
	  $lengthC = 5;
	  $lengthN = 5;
	  //characters
	  $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	  $string = '';
	  for ($p = 0; $p < $lengthC; $p++) {
	   $string .= $characters[mt_rand(0, strlen($characters) - 1)];
	  }
	   
	  //numbers
	  $numbers = "0123456789";
	  $numeric = '';
	  for ($p = 0; $p < $lengthC; $p++) {
	   $numeric .= $numbers[mt_rand(0, strlen($numbers) - 1)];
	  }
	  echo str_shuffle($numeric.$string);
	  
	}//end fct
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */